/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import DTO.NguoiDung_DTO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import DTO.DonHang_DTO;

/**
 *
 * @author xxx
 */
public class DonHang_DAO {
    
    Database db = new Database();
    Connection conn = null;
    PreparedStatement pst = null;
    
    // lay danh sach DonHang
    public ArrayList<DonHang_DTO> Lay_DsDonhang() throws Exception
    {
        ArrayList<DonHang_DTO> arr = new ArrayList<DonHang_DTO>(); 
        String sql = "SELECT * FROM DonHang ";       
        conn = db.open();
        pst = conn.prepareStatement(sql);
        
        ResultSet rs = pst.executeQuery();
        
        while (rs.next())
        {
            DonHang_DTO dh = new DonHang_DTO();   
            dh.setIDDonHang(rs.getInt("IDDonHang"));
            dh.setIDKhachhang(rs.getInt("IDNguoiDung"));
            dh.setThanhTien(rs.getInt("ThanhTien"));
            dh.setNgayDat(rs.getDate("NgayDat"));
            dh.setTinhTrang(rs.getInt("TinhTrang"));
           
            arr.add(dh);
        }
        db.close();
        return arr;
        
    }
    
    //Tim kiem don hang theo thanh tien
    
    public ArrayList<DonHang_DTO> timkiemdonhang_theothanhtien(int thanhtien) throws Exception
    {
         ArrayList<DonHang_DTO> arr = new ArrayList<DonHang_DTO>(); 
        String sql = "SELECT * FROM DonHang where ThanhTien >= " + thanhtien;
        
        conn = db.open();
        pst = conn.prepareStatement(sql);
        
        ResultSet rs = pst.executeQuery();
        
        while (rs.next())
        {
             DonHang_DTO dh = new DonHang_DTO();
        
            dh.setIDDonHang(rs.getInt("IDDonHang"));
            dh.setIDKhachhang(rs.getInt("IDNguoiDung"));
            dh.setThanhTien(rs.getInt("ThanhTien"));
            dh.setNgayDat(rs.getDate("NgayDat"));
            dh.setTinhTrang(rs.getInt("TinhTrang"));
            
            arr.add(dh);
        }
       
         db.close();
        return arr;
    }
    
    
    
    
}
